home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / UNIX.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  6KB  |  326 lines

  1. #include "logo.h"
  2. #include "globals.h"
  3. #include <dos.h>
  4. #include <dir.h>
  5.  
  6. #ifdef __ZTC__
  7. #include <signal.h>
  8. #define SIGQUIT SIGTERM
  9. #endif
  10.  
  11. #ifndef TIOCSTI
  12. #include <setjmp.h>
  13. jmp_buf iblk_buf;
  14. #endif
  15.  
  16. char combo_buff[MAX_BUFFER_SIZE];
  17.  
  18. void mputcombobox(char *str) /*routine*/
  19.    {
  20.    char tempbuff[MAX_BUFFER_SIZE];
  21.    
  22.    int i;
  23.    int j;
  24.    int k;
  25.    int l;   
  26.    
  27.    l=strlen(combo_buff);
  28.    strncat(combo_buff,str,MAX_BUFFER_SIZE-l);
  29.    
  30.    k=0;
  31.    tempbuff[k] = '\0';
  32.    
  33.    i=strlen(combo_buff);
  34.    
  35.    for (j=0;j<i;j++)
  36.       {
  37.       if (combo_buff[j] == '\n')
  38.          {
  39.          tempbuff[k] = '\0';
  40.          putcombobox(tempbuff);
  41.          k = 0;
  42.          tempbuff[k] = '\0';
  43.          }
  44.       else
  45.          {
  46.          tempbuff[k++] = combo_buff[j];
  47.          }
  48.       }
  49.    
  50.    if (k!=0)
  51.       {
  52.       tempbuff[k] = '\0';
  53.       putcombobox(tempbuff);
  54.       }
  55.    
  56.    combo_buff[0] = '\0';
  57.    
  58.    }
  59.  
  60. void putcombochar(char c) /*routine*/
  61.    {
  62.    int i;
  63.    
  64.    if (c == '\n')
  65.       {
  66.       putcombobox(combo_buff);
  67.       combo_buff[0] = '\0';
  68.       }
  69.    else
  70.       {
  71.       i = strlen(combo_buff);
  72.       if ((i+2) < MAX_BUFFER_SIZE)
  73.          {
  74.          combo_buff[i] = c;
  75.          combo_buff[i+1] = '\0';
  76.          }
  77.       else
  78.          {
  79.          combo_buff[i] = '\n';
  80.          combo_buff[i+1] = '\0';
  81.          putcombobox(combo_buff);
  82.          combo_buff[0] = c;
  83.          combo_buff[1] = '\0';
  84.          }
  85.       
  86.       }
  87.    
  88.    }
  89.  
  90. void nputs(char *str) /*routine*/
  91.    {
  92.    char c;
  93.    
  94.    while((c = *str++) != 0) putcombochar(c);
  95.    
  96.    }
  97.  
  98. int printfx(char *fmt) /*routine*/
  99.    {
  100.    mputcombobox(fmt);
  101.    
  102.    return(strlen(fmt));
  103.    }
  104.  
  105. int printfx(char *fmt,char *str) /*routine*/
  106.    {
  107.    long cnt;                /* Result of SPRINTF for return */
  108.    char buff[MAX_BUFFER_SIZE];
  109.    
  110.    cnt = sprintf(buff, fmt, str);
  111.    
  112.    mputcombobox(buff);
  113.    
  114.    return(cnt);
  115.    }
  116.  
  117. int printfx(char *fmt,long str) /*routine*/
  118.    {
  119.    long cnt;                /* Result of SPRINTF for return */
  120.    char buff[MAX_BUFFER_SIZE];
  121.    
  122.    cnt = sprintf(buff, fmt, str);
  123.    
  124.    mputcombobox(buff);
  125.    
  126.    return(cnt);
  127.    }
  128.  
  129. int printfx(char *fmt,long str, char *str2) /*routine*/
  130.    {
  131.    long cnt;                /* Result of SPRINTF for return */
  132.    char buff[MAX_BUFFER_SIZE];
  133.    
  134.    cnt = sprintf(buff, fmt, str, str2);
  135.    
  136.    mputcombobox(buff);
  137.    
  138.    return(cnt);
  139.    }
  140.  
  141. int printfx(char *fmt,short str, long str2) /*routine*/
  142.    {
  143.    long cnt;                /* Result of SPRINTF for return */
  144.    char buff[MAX_BUFFER_SIZE];
  145.    
  146.    cnt = sprintf(buff, fmt, str, str2);
  147.    
  148.    mputcombobox(buff);
  149.    
  150.    return(cnt);
  151.    }
  152.  
  153. int printfx(char *fmt,short str, short str2) /*routine*/
  154.    {
  155.    long cnt;                /* Result of SPRINTF for return */
  156.    char buff[MAX_BUFFER_SIZE];
  157.    
  158.    cnt = sprintf(buff, fmt, str, str2);
  159.    
  160.    mputcombobox(buff);
  161.    
  162.    return(cnt);
  163.    }
  164.  
  165. long putcharx(long ch) /*routine*/
  166.    {
  167.    putcombochar((char)ch);
  168.    
  169.    return(ch);
  170.    }
  171.  
  172. long putsx(const char *ch) /*routine*/
  173.    {
  174.    mputcombobox((char *)ch);
  175.    
  176.    return(1);
  177.    }
  178.  
  179. NODE *lpushdir(NODE *arg) /*routine*/
  180.    {
  181.    char fname[80];
  182.    
  183.    cnv_strnode_string(fname, arg);
  184.    
  185.    if (chdir(fname))
  186.       {
  187.       printfx("Could not Push to directory %s\n",fname);
  188.       }
  189.    else
  190.       {
  191.       getcwd(fname,80);
  192.       printfx("Pushed to %s\n",fname);
  193.       }
  194.    
  195.    return (UNBOUND);
  196.    }
  197.  
  198. NODE *lpopdir(void) /*routine*/
  199.    {
  200.    char fname[80];
  201.    
  202.    chdir("..");
  203.    getcwd(fname,80);
  204.    printfx("Popped to %s\n",fname);
  205.    
  206.    return (UNBOUND);
  207.    }
  208.  
  209. NODE *lmkdir(NODE *arg) /*routine*/
  210.    {
  211.    char fname[80];
  212.    
  213.    cnv_strnode_string(fname, arg);
  214.    
  215.    if (mkdir(fname))
  216.       {
  217.       printfx("Failed to create directory %s\n",fname);
  218.       }
  219.    else
  220.       {
  221.       chdir(fname);
  222.       printfx("Now in newly created directory %s\n",fname);
  223.       }
  224.    
  225.    return (UNBOUND);
  226.    }
  227.  
  228. NODE *lrmdir(NODE *arg) /*routine*/
  229.    {
  230.    char fname[80];
  231.    
  232.    cnv_strnode_string(fname, arg);
  233.    
  234.    if (rmdir(fname))
  235.       {
  236.       printfx("Failed to remove directory %s\n",fname);
  237.       printfx("Make sure the directory is empty before trying to remove\n");
  238.       }
  239.    else
  240.       {
  241.       printfx("Logo directory %s removed\n",fname);
  242.       }
  243.    
  244.    return (UNBOUND);
  245.    }
  246.  
  247. NODE *ldir(void) /*routine*/
  248.    {
  249.    struct find_t ffblk;
  250.    int done;
  251.    
  252.    done = _dos_findfirst("*.*",0,&ffblk);
  253.    while (!done)
  254.       {
  255.       if (ffblk.attrib != FA_DIREC) printfx("File %s\n",ffblk.name);
  256.       done = _dos_findnext(&ffblk);
  257.       }
  258.    
  259.    done = _dos_findfirst("*.*",FA_DIREC,&ffblk);
  260.    while (!done)
  261.       {
  262.       if (ffblk.attrib == FA_DIREC) printfx("Directory %s\n",ffblk.name);
  263.       done = _dos_findnext(&ffblk);
  264.       }
  265.    
  266.    return(UNBOUND);
  267.    }
  268.  
  269.    void unblock_input() {
  270.       if (input_blocking) {
  271.       input_blocking = 0;
  272. #ifdef TIOCSTI
  273.       ioctl(0,TIOCSTI,"\n");
  274. #else
  275.       longjmp(iblk_buf,1);
  276. #endif
  277.       }
  278.    }
  279.  
  280. #ifdef __ZTC__
  281. void logo_stop(int sig)
  282. #else
  283. void logo_stop(int sig)
  284. #endif
  285.    {
  286.    to_pending = 0;
  287. #ifndef unix
  288.    err_logo(STOP_ERROR,NIL);
  289. #else
  290.       if (ufun != NIL) {
  291.       err_logo(STOP_ERROR,NIL);
  292.       } else {
  293.       new_line(stdout);
  294.       }
  295. #endif
  296. #ifndef bsd
  297.    signal(SIGINT, logo_stop);
  298. #endif
  299.    unblock_input();
  300.    }
  301.  
  302. #ifdef __ZTC__
  303. void logo_pause(int sig)
  304. #else
  305. void logo_pause(int sig) //
  306. #endif
  307.    {
  308.    to_pending = 0;
  309. #ifdef bsd
  310.    sigsetmask(0);
  311. #else
  312.    signal(SIGQUIT, logo_pause);
  313. #endif
  314. #ifndef unix
  315.    lpause();
  316. #else
  317.       if (ufun != NIL) {
  318.       lpause();
  319.       } else {
  320.       new_line(stdout);
  321.       unblock_input();
  322.       }
  323. #endif
  324.    }
  325.  
  326.